//
//  HWLiveAssetsController.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/1/19.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit
import JXSegmentedView
class HWLiveAssetsController: HWBaseViewController {
    var tableView:UITableView!
    
    let tableViewProtocol = HWLiveAssetsProtocol()
    let httpManager = HWLiveAssetsHttpManager()
    override func viewDidLoad() {
        super.viewDidLoad()

        initUI()
        
        initFrame()
        
        loadData()
        
        addAction()
        
    }
    
}

extension HWLiveAssetsController {
    private func initUI() -> Void {
        navigationView.backButton.isHidden = false
        
        tableView = UITableView.init(frame: CGRect.zero, style: UITableView.Style.plain)
        tableView.delegate = tableViewProtocol
        tableView.dataSource = tableViewProtocol
        tableView.backgroundColor = UIColor.colorWithHexString(hexString: "#F7F7F7")
        tableView.separatorStyle = .none
        tableView.rowHeight = UITableView.automaticDimension
        tableView.estimatedRowHeight = 40
        tableView.estimatedSectionHeaderHeight = 0
        tableView.estimatedSectionFooterHeight = 0
        tableView.showsVerticalScrollIndicator = false
        view.addSubview(tableView)
        if #available(iOS 15.0, *) {
            self.tableView.sectionHeaderTopPadding = 0
        } else {
            // Fallback on earlier versions
        }
    }
    
    private func initFrame() -> Void {
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
}

extension HWLiveAssetsController:JXSegmentedListContainerViewListDelegate{
    func listView() -> UIView {
        return view
    }
}

extension HWLiveAssetsController {
    func loadData() -> Void {
        httpManager.getLiveAssetsInfo { model in
            self.tableViewProtocol.model = model
            self.tableView.reloadData()
        } failure: { error in
            
        }

    }
}

extension HWLiveAssetsController {
    func addAction() -> Void {
        self.tableViewProtocol.didClickRow = {
            url in
            let webVC = HWPayWebController()
            webVC.urlString = url
            self.navigationController?.pushViewController(webVC, animated: true)
        }
    }
}
